__author__ = 'vladbranzei'

import requests

base_url = "http://services-vodagames.rhcloud.com"

def check_freya():
    global base_url

    #1. authorize
    #2. authenticate
    #3. change password
    #4. authorize with old password
    #5  authorize with new password
    #6  add permissions
    #7 remove permissions

    #1 authorize
    authorize_url = base_url + 'freya/authorize'
    payload = {'credentials': 'anonymous:testuser', 'game': '1512', 'scopes': 'auth', 'password': 'testpassword'}
    r = requests.post(authorize_url, payload)

    #2 authenticate
    authenticate_url = base_url + 'freya/authenticate'
    payload = {'credentials': 'anonymous:testuser', 'game': '1512'}
    r = requests.get(authenticate_url, payload)

    #3 change password
    change_pwd_url = base_url + 'freya/change_password'
    payload = {'new_password': 'testpassword_new'}
    r = requests.post(change_pwd_url, payload)

    #4
    authorize_url = base_url + 'freya/authorize'
    payload = {'credentials': 'anonymous:testuser', 'game': '1512', 'scopes': 'auth', 'password': 'testpassword'}
    r = requests.post(authorize_url, payload)

    #5 authorize with new password
    authorize_url = base_url + 'freya/authorize'
    payload = {'credentials': 'anonymous:testuser', 'game': '1512', 'scopes': 'auth', 'password': 'testpassword_new'}
    r = requests.post(authorize_url, payload)

    #6 add permissions
    add_permissions_url = base_url + 'freya/add_permissions'
    payload = {'credentials': 'anonymous:testuser', 'token': '', 'permissions': [' ']}
    r = requests.post(add_permissions_url, payload)

    #7 remove permissions
    remove_permissions_url = base_url + 'freya/remove_permissions'
    payload = {'credentials': 'anonymous:testuser', 'token': '', 'permissions':[' ']}
    r = requests.post(remove_permissions_url, payload)

def check_ulise():
    global base_url
    #1 authorize for leaderboard scope
    #2 post entry to a leaderboard
    #3 authorize with another user
    #4 post entry to the same leaderboard
    #5 get leaderboard to see entries using offset 0 limit 100
    #6 get leaderborad to see entries using offset 100 limit 200

    authorize_url = base_url + 'freya/authorize'
    payload = {'credentials': 'anonymous:testuser', 'scopes': 'leaderboard', 'game': '1512', 'password': 'testpassword_new'}
    r = requests.post(authorize_url, payload)

    post_url = base_url + 'ulise/test_leaderboard/desc/post'
    payload = {'token': '', 'score': 15, 'display_name': ''}
    r = requests.post(post_url, payload)

    authorize_url = base_url + 'freya/authorize'
    payload = {'credentials': 'anonymous:testuser2', 'scopes': 'leaderboard', 'game': '1512', 'password':'testpassword2'}
    r = requests.post(post_url, payload)

    post_url = base_url + 'ulise/test_leaderboard/desc/post'
    payload = {'token': '', 'scope': 20, 'display_name': 'anonymous:testuser2'}
    r = requests.post(post_url, payload)

    get_leaderboard_url = base_url + '/ulise/test_leaderboard/desc'
    payload = {'token':'', 'offset':0, 'limit':100}
    r = requests.post(get_leaderboard_url, payload)

    payload = {'token':'', 'offset':100, 'limit':100}
    r = requests.post(get_leaderboard_url, payload)

if __name__ == '__main__':
    check_freya()